package cn.yr.oss.configuration;


import cn.yr.oss.OssKit;
import cn.yr.oss.QnyOss;
import cn.yr.oss.properties.OssProperties;
import cn.yr.oss.properties.OssQnyProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 七牛云配置
 *
 * @author Lang 1102076808@qq.com
 * @date 2021-04-08 22:33
 */

@Configuration
@EnableConfigurationProperties({OssQnyProperties.class, OssProperties.class})
@ConditionalOnProperty(
		prefix = "oss",
		name = "sdk",
		havingValue = "qny"
)
public class OssQnyConfiguration {

	@Autowired
	private OssQnyProperties ossQnyProperties;
	@Autowired
	private OssProperties ossProperties;

	@Bean("qnyOss")
	public QnyOss qnyOss(){
		return new QnyOss(ossQnyProperties.getAccessKey(),ossQnyProperties.getSecretKey()
				,ossQnyProperties.getBucket(),ossProperties.getDomain());
	}

	@Bean("ossKit")
	public OssKit ossKit(){
		OssKit ossKit = new OssKit();
		ossKit.setOss(qnyOss());
		return ossKit;
	}
}
